/**
 * 
 */

$(document).ready(function(){
	
	//create account
	$("#create-acount-button-id").click(function(event){
		
		createMyschoolAccount();
	});
	
	//login to account

	$("#signin-button-id").click(function(event){
		
		loginToMyschool();
	});
	
$("#forgot-password-button-id").click(function(event){
		
		forgotPassword();
	});

/*//register link
$("#regsiter-link-id").click(function(event){
	
	registerMe();
});	*/
});



	//window.setInterval(updateBundleInfo,10000);
	//Method to create account
	function createMyschoolAccount(){

			//Create the ajax call
			$.ajax({
				type: 'POST',
				url: 'login/createAccount.htm',
				data: $("#create-account-form-id").serialize(),
				timeout: 5000,
				success: function(data) {
				 if (data) {
					$('#createaccount-message-div').html( data.message);
				 }	},
				error: function (XMLHttpRequest, textStatus, errorThrown) {
						$('#createaccount-message-div').html("Error creating account to myschool.Error:"+errorThrown+"<br/>Please refresh the web page ");
				},
				dataType: 'json'
			});
	}

	//Method to validate account login
	function loginToMyschool(){

			//Create the ajax call
			$.ajax({
				type: 'POST',
				url: 'login/processLogin.htm',
				data: $("#signin-form-id").serialize(),
				timeout: 5000,
				success: function(data) {
				 if (data) {
					$('#signin-message-id').html( data.message);
					
					if(data.registrationStatus){
					
					if(data.registrationStatus=='NR'){
						$('#signin-message-id').html(" <br/> You have not registered with any school.Please register.");
						$('#register-message-id').show();
						$('#register-school-message-id').show();
						
					}
					if(data.registrationStatus=='PR'){
						$('#signin-message-id').html(" <br/> Your registration is pending,Please wait till adminstration responds.");
						$('#register-message-id').show();
						
					}
					//registration rejected
					if(data.registrationStatus=='RR'){
						$('#signin-message-id').html(" <br/> Your registration is rejected,Please contact adminstration.");
					}
					//direct the user to home page or close the dialog
					if(data.registrationStatus=='RA'){
						closeDialog();
					}
					
				 }
					closeDialog();
				 }	},
				error: function (XMLHttpRequest, textStatus, errorThrown) {
						$('#signin-message-id').html("Error loging to myschool.Error:"+errorThrown+"<br/>Please refresh the web page ");
				},
				dataType: 'json'
			});
	}

	//Method to handle forgot password
	function forgotPassword(){
             
			//Create the ajax call
			$.ajax({
				type: 'POST',
				url: 'login/forgotPassword.htm',
				data: $("#forgotpassword-form-id").serialize(),
				timeout: 5000,
				success: function(data) {
				 if (data) {
					$('#forgotpassword-message-id').html( data.message);
				 }	},
				error: function (XMLHttpRequest, textStatus, errorThrown) {
						$('#forgotpassword-message-id').html("Error reseting password:"+errorThrown+"<br/>Please refresh the web page ");
				},
				dataType: 'json'
			});
	}
	
	
	function registerMe(){

		alert("hiii");
		$("#signin-form-id").action="register/preRegister.htm";
		$("#signin-form-id").submit();
		
	}
